﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.Mapping;
using NhibernateUtil;

namespace Nissen_Dao
{
	public abstract class DaoBase 
	{
		protected virtual ISession Session
		{
			get
			{
				ISession session = NhibernateHelper.GetCurrentSession(true);
				return session;

			}

		}
		protected virtual ISessionFactory SessionFactory
		{
			get
			{

				return NhibernateHelper.SessionFactory;

			}

		}
		/// <summary>
		/// 执行更新Sql
		/// </summary>
		/// <param name="sql"></param>
		public void ExcuteUpdateSql(string sql)
		{
			NhibernateHelper.ExcuteUpdateSql(sql);
		}

		/// <summary>
		/// 初始化一个延迟加载的列表
		/// </summary>
		/// <param name="list"></param>
		public void InitializeList(object list)
		{
			NHibernateUtil.Initialize(list);
		}

		/// <summary>
		/// 对象是否被初始化
		/// </summary>
		/// <param name="obj"></param>
		/// <returns></returns>
		public bool IsInitializeObject(object obj)
		{
			return NHibernateUtil.IsInitialized(obj);
		}

		/// <summary>
		/// 设置不向数据库中写入任何数据
		/// </summary>
		public void SetNonFlush()
		{
			Session.FlushMode = FlushMode.Never;
		}

		
	}

}
